package cn.tedu.eb_film.service.impl;

import cn.tedu.eb_film.ex.ServiceException;
import cn.tedu.eb_film.mapper.EmployeeMapper;
import cn.tedu.eb_film.mapper.OrderMapper;
import cn.tedu.eb_film.pojo.dto.EmployeeAddNewDTO;
import cn.tedu.eb_film.pojo.dto.EmployeeUpdateDTO;
import cn.tedu.eb_film.pojo.dto.OrderAddNewDTO;
import cn.tedu.eb_film.pojo.dto.OrderUpdateDTO;
import cn.tedu.eb_film.pojo.entity.Employee;
import cn.tedu.eb_film.pojo.entity.Order;
import cn.tedu.eb_film.pojo.vo.EmployeeListItemVO;
import cn.tedu.eb_film.pojo.vo.EmployeeStandardVO;
import cn.tedu.eb_film.pojo.vo.OrderListItemVO;
import cn.tedu.eb_film.pojo.vo.OrderStandardVO;
import cn.tedu.eb_film.service.EmployeeService;
import cn.tedu.eb_film.service.OrderService;
import cn.tedu.eb_film.utils.ServiceCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 订单表服务实现类
 *
 * @author zzzzc
 * @since 2023-03-18 18:38:25
 */
@Slf4j
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;

    public OrderServiceImpl(){
        log.debug("创建业务类对象：OrderServiceImpl");
    }

    @Override
    public void addNew(OrderAddNewDTO orderAddNewDTO) {
        Order order = new Order();
        BeanUtils.copyProperties(orderAddNewDTO,order);
        log.debug("即将执行插入数据，参数：{}",order);
        orderMapper.insert(order);
    }



    @Override
    public void updateInfoById(Long id, OrderUpdateDTO orderUpdateDTO) {
        OrderStandardVO standardById = orderMapper.getStandardById(id);
        if (standardById==null){
            String message = "修改失败，数据不存在";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERROR_NOT_FOUND,message);
        }
        Order order = new Order();
        BeanUtils.copyProperties(orderUpdateDTO,order);
        order.setId(id);
        orderMapper.update(order);
    }

    @Override
    public OrderStandardVO getStandardById(Long id) {
        log.debug("开始处理【根据订单id查询详情】的业务，ID：{}", id );
        OrderStandardVO standardById = orderMapper.getStandardById(id);
        if (standardById==null){
            String message = "查询失败，数据不存在";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERROR_NOT_FOUND,message);
        }
        return standardById;
    }

    @Override
    public List<OrderListItemVO> list() {
        log.debug("开始处理【查询详情列表】的业务，无参数");
        List<OrderListItemVO> list = orderMapper.list();
        return list;
    }
}
